/**
 * 
 */
package com.readnote.auto;

import java.util.Date;
import java.util.List;

import com.cr.backbone.hibenate.AppBaseServiceImpl;
import com.cr.backbone.util.UtilsDateTime;
import com.readnote.book.dao.UserNoteDAO;
import com.readnote.book.model.UserNote;
import com.readnote.user.dao.UserDAO;
import com.readnote.user.model.User;

/**
 * @project RaedNote
 * @version 1.0
 * @company 
 * @fileType UserNoteReviewServiceImp UserNoteReviewServiceImp.java
 * @author huxh
 * @date 2012-7-17
 */
public class UserNoteReviewServiceImp extends AppBaseServiceImpl<UserNote>  {

	private Integer[] REVIEW_AFTER_DAYS={1,3,7,15,30};

	private UserDAO userDAO;//用户dao
	
	public UserNoteDAO getDAO() {
		return (UserNoteDAO) dao;
	}
	
	/**
	 * 查询出所有用户的笔记，根据笔记创建的日期date,在指定date+1、date+3、date+7、date+15、date+30 这几天早晨9点，将笔记作为邮件，发送给用户
	 * 
	 * @author huxh
	 * @date 2012-7-17
	 */
	public void findUserNoteAndReviewByMail(){
		
		List<User> users=userDAO.getList();//all user
		
		for(User user:users){
			List<UserNote> usernotes= getDAO().getListUserNoteByUser(user);
			
			for(UserNote userNote : usernotes){
				if(isSendMailReviewDate( userNote.getCreateDate() )){
					sendMailReviewByUserNote(userNote);
				}
			}
		}
	}

	/**
	 * 
	 * @param userNote
	 * @author huxh
	 * @date 2012-7-17 
	 */
	private void sendMailReviewByUserNote(UserNote userNote) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * 
	 * @param createDate
	 * @return
	 * @author huxh
	 * @date 2012-7-17 
	 */
	private boolean isSendMailReviewDate(Date createDate) {
		boolean sendMailReviewDate=false;//
		if(createDate == null )
			return sendMailReviewDate;
		
		String format="yyyy-MM-dd";
		int AFTER_REVIEW_DAY=0;
		Date nowDate=new Date();//当前日期
		for(Integer i: REVIEW_AFTER_DAYS){
			Date afterDate=UtilsDateTime.getAfterDate(createDate, 0, 0, AFTER_REVIEW_DAY);//review日期
			if( UtilsDateTime.format(nowDate, format).equals(UtilsDateTime.format(afterDate, format))  ){
				
			}
		}
		
		
		return sendMailReviewDate;
	}
	
	
	
}
 